home *** CD-ROM | disk | FTP | other *** search
- /* imagelab.c
- *
- * dieter fiebelkorn 24.08.91
- *
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <math.h>
- #include <vdi.h>
- #include <aes.h>
- #include "image.h"
- #include "imageopt.h"
- #include "module.h"
-
-
-
- int imagelabIdent(LOAD_Structure *loadS, unsigned int verbose)
- {
- ZFILE *zf;
- char header[10];
- int r, w, h;
- int colors;
- char *fullname = loadS->in_filename;
-
- if (! (zf= (*loadS->input.open)(fullname, 0x00))) {
- (*loadS->error.printerr)(" Error reading ImageLab!");
- return(0);
- }
- switch ((int)(*loadS->input.read)(zf, header, 10UL)) {
- case 10:
- if (strncmp(header, "B&W256", 6) == 0) {
- w = *((unsigned short*)&header[6]);
- h = *((unsigned short*)&header[8]);
- colors = 256;
- (*loadS->print.printout)("%s\n is a %dx%d Imagelab picture\n",fullname , w, h);
- r = 1;
- break;
- }
- if ((*(long*)header == 0x0F0F0001L) && (*(short*)&header[8] == 0x0001)) {
- w = *((unsigned short*)&header[4]);
- h = *((unsigned short*)&header[6]);
- colors = 256;
- (*loadS->print.printout)("%s\n is a %dx%d Videodigitizer picture\n",fullname , w, h, colors);
- r = 1;
- break;
- }
- r= 0;
- break;
-
- default:
- r= 0;
- break;
- }
- (*loadS->input.close)(zf);
- return(r);
- }
-
-
-
- Image *imagelabLoad(LOAD_Structure *loadS, unsigned int verbose)
- {
- ZFILE *zf;
- Image *image;
- unsigned char header[12];
- int w, h, planes, colors, i, j, id;
- char *fullname = loadS->in_filename;
- int id_only = loadS->identify_only;
-
- id = imagelabIdent(loadS, verbose);
- if (id_only)
- return((Image*)id);
- if (id == 0)
- return(NULL);
-
- zf= (*loadS->input.open)(fullname, 0x00);
- (*loadS->input.read)(zf, header, 10UL);
- if (strncmp(header, "B&W256", 6) == 0) {
- w = *((unsigned short*)&header[6]);
- h = *((unsigned short*)&header[8]);
- } else {
- w = *((unsigned short*)&header[4]);
- h = *((unsigned short*)&header[6]);
- }
- planes = 8;
- colors = 256;
-
- image= (*loadS->images.newRGBImage)(NULL, (unsigned int) w, (unsigned int) h, planes);
- if (!image) {
- (*loadS->input.close)(zf);
- return (image);
- }
-
- if ((*loadS->input.read)(zf, image->data, (unsigned long)w * (unsigned long)h) != (unsigned long)w * (unsigned long)h)
- (*loadS->print.printout)(" Bad read on image data\n");
-
- for (i= 0, j = colors - 1; i < colors; i++, j--) {
- image->rgb.red[i] = (unsigned int) ( ((unsigned long) (255-j)) << 8);
- image->rgb.green[i] = (unsigned int) ( ((unsigned long) (255-j)) << 8);
- image->rgb.blue[i] = (unsigned int) ( ((unsigned long) (255-j)) << 8);
- }
- image->rgb.used = 256;
- image->title= DupString(loadS, fullname);
-
- (*loadS->input.close)(zf);
- return (image);
- }
-